package com.ghsc.ghxc.jsb.ui.my.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.bean.SysConfigResult
import com.ghsc.ghxc.jsb.ui.my.bean.LogOffResult
import com.ghsc.ghxc.jsb.ui.my.bean.OssTokenResultDataBean
import com.ghsc.ghxc.jsb.ui.my.bean.UserResultDataBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.my.activity
 * 类名：SetUpViewModel
 * 创建时间：2024/4/24 20:07
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class SetUpViewModel  : BaseViewModel() {



    /**
     * 个人中心
     */
    val onUserInfoData: MutableLiveData<BaseResponse<UserResultDataBean>> = MutableLiveData()
    fun onUserInfoMethod() {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onUserInfoData() }
            executeResponse(
                response,
                { onUserInfoData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }

    }
    /**  配置 **/
    val onSysConfigData by lazy { MutableLiveData<SysConfigResult>() }
    fun onSysConfigMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onSysConfigData(paras) }
            executeResponse(
                response,
                { onSysConfigData.value = response.data },
                {
                    againLoginMsg.value = response.msg
                },
            ) { errorMsg.value = response.msg }
        }
    }

    /** 阿里云oos **/
    val onAliYunOosData: MutableLiveData<BaseResponse<OssTokenResultDataBean>> = MutableLiveData()
    fun onAliYunOosMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onAliYunOosData(paras) }
            executeResponse(
                response,
                { onAliYunOosData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }

    /**
     * 注销index
     */
    val onZhuXiaoIndexData: MutableLiveData<BaseResponse<LogOffResult>> = MutableLiveData()
    fun onZhuXiaoIndexMethod(paras: String ) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZhuXiaoIndexData(paras) }
            executeResponse(
                response,
                { onZhuXiaoIndexData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }
    /**
     * 注销
     */
    val onZhuXiaoData: MutableLiveData<BaseResponse<LogOffResult>> = MutableLiveData()
    fun onZhuXiaoMethod(paras: String ) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZhuXiaoData(paras) }
            executeResponse(
                response,
                { onZhuXiaoData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }

    /**
     * 修改用户信息
     */
    val updateUserInfoData: MutableLiveData<BaseResponse<Any>> = MutableLiveData()
    fun updateUserInfoMethod(paras: String ) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.updateUserInfoData(paras) }
            executeResponse(
                response,
                { updateUserInfoData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }
}